﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Mechanics.GameEventMechanics {
    import Mechanics.GameMechanicInterfaces.*;
    import Mechanics.*;
    import flash.utils.*;
    import Classes.*;
    import com.adobe.utils.*;

    public class NeighborVisitRewardMechanic implements IActionGameMechanic, IMultiPickSupporter, IToolTipModifier {

        private var m_owner:MechanicMapResource;
        private var m_config:MechanicConfigData;

        public function initialize(_arg1:IMechanicUser, _arg2:MechanicConfigData):void{
            this.m_owner = (_arg1 as MechanicMapResource);
            this.m_config = _arg2;
        }
        public function hasOverrideForGameAction(_arg1:String):Boolean{
            return (this.canExecute());
        }
        protected function canExecute():Boolean{
            var _local1:String = Global.player.snUser.uid;
            var _local2:Dictionary = this.m_owner.getDataForMechanic(this.m_config.type);
            var _local3:int = this.getVisitorLimit();
            var _local4:Boolean;
            if (_local2){
                _local3 = DictionaryUtil.getKeys(_local2).length;
                _local4 = !((_local2[Global.player.uid] == null));
            };
            return (((((Global.isVisiting()) && ((_local3 < this.getVisitorLimit())))) && (!(_local4))));
        }
        public function executeOverrideForGameEvent(_arg1:String, _arg2:Array=null):MechanicActionResult{
            if (!this.canExecute()){
                return (new MechanicActionResult(false, true, false, null));
            };
            var _local3:Dictionary = this.m_owner.getDataForMechanic(this.m_config.type);
            var _local4:String = Global.player.snUser.uid;
            _local3[_local4] = this.getRewardName();
            this.m_owner.setDataForMechanic(this.m_config.type, _local3);
            var _local5:int = DictionaryUtil.getKeys(_local3).length;
            this.handleReward();
            var _local6:String = Global.getVisiting();
            var _local7:Boolean;
            var _local8:Boolean;
            var _local9:Boolean;
            var _local10:Object = {neighbor:_local6};
            return (new MechanicActionResult(_local7, _local8, _local9, _local10));
        }
        public function handleReward():void{
            var _local1:String;
            if (((this.m_config) && (this.m_config.params))){
                _local1 = this.m_config.params["rewardType"];
            };
            if (_local1 == null){
                throw (new Error("rewardType was not specified in NeighborVisitRewardMechanic."));
            };
            var _local2:int = this.getRewardQuantity();
            var _local3:Array = new Array();
            _local3.push([Global.gameSettings.getDooberFromType(_local1, _local2), _local2]);
            Global.world.dooberManager.createBatchDoobers(_local3, null, this.m_owner.getPosition().x, this.m_owner.getPosition().y);
        }
        public function getVisitorLimit():int{
            if (this.m_config != null){
                return (int(this.m_config.params["visitorLimit"]));
            };
            throw (new Error("MechanicConfigData not initialized"));
        }
        public function getRewardName():String{
            if (this.m_config != null){
                return (String(this.m_config.params["rewardName"]));
            };
            throw (new Error("MechanicConfigData not initialized"));
        }
        public function getRewardQuantity():int{
            if (this.m_config != null){
                return (int(this.m_config.params["rewardQuantity"]));
            };
            throw (new Error("MechanicConfigData not initialized"));
        }
        public function isVisitor(_arg1:String):Boolean{
            var _local2:Boolean;
            var _local3:Dictionary = this.m_owner.getDataForMechanic(this.m_config.type);
            if (((_local3) && (_local3.hasOwnProperty(_arg1)))){
                _local2 = true;
            };
            return (_local2);
        }
        public function isVisitEnabled():Boolean{
            return (true);
        }
        public function getPick():String{
            return (this.m_config.params["pick"]);
        }
        public function getToolTipStatus():String{
            var _local1:String;
            if (this.canExecute()){
                if (Global.player.checkVisitorEnergy(1)){
                    _local1 = ZLoc.t("Main", "ClickToSendTour");
                } else {
                    _local1 = ZLoc.t("Main", "NeedEnergy", {amount:1});
                };
            };
            return (_local1);
        }
        public function getToolTipAction():String{
            var _local1:String;
            return (_local1);
        }

    }
}//package Mechanics.GameEventMechanics 
